package com.xcf.controller.business.common;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;


import com.xcf.controller.base.BaseController;
import com.xcf.service.business.common.boatbasedata.BoatBaseDataManageService;
import com.xcf.util.PageData;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/** 
 * 船舶基础资料管理
 * 类名称：BoatBaseDataManageController
 * 创建人：tanwei
 * 更新时间：2017年11月23日
 * @version
 */
@Controller
@RequestMapping("/boatBaseDataManage")
public class BoatBaseDataManageController extends BaseController{
	@Resource
	private BoatBaseDataManageService boatBaseDataManageService;
	/**
	 * 列表查询
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/list")
	public ModelAndView boatBaseDataManageList()throws Exception{
		PageData pd = new PageData();
		pd = this.getPageData();
		ModelAndView view = new ModelAndView();
		List<PageData>boatBaseDataManage = boatBaseDataManageService.findBoatBaseDataManageInfo(pd);
		view.addObject("boatBaseDataManage", boatBaseDataManage);
		view.setViewName("/business/common/boatbasedata/boat_base_data_manage");
		return view;
		
	}
	/**
	 * 保存或修改船舶基础资料
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/saveOrUpdateBoatBaseDataManage")
	@ResponseBody
	public String saveOrUpdateBoatBaseDataManage()throws Exception{
		PageData pd = new PageData();
		pd = this.getPageData();

		if(pd.getString("ID")==null || pd.getString("ID")==""){
			boatBaseDataManageService.saveBoatDataManageInfo(pd);
			}else{
				boatBaseDataManageService.updateBoatDataManageInfo(pd);
			}
		return null;
		
	}
	/**
	 * 修改跳转页面
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/editBoatBaseDataManage")
	public ModelAndView editBoatBaseDataManage()throws Exception{
		PageData pd = new PageData();
		pd = this.getPageData();
		ModelAndView view = new ModelAndView();
		pd = boatBaseDataManageService.findBoatBaseDataManageById(pd);
		view.addObject("pd",pd);
		view.setViewName("/business/common/boatbasedata/boat_base_data_manage_edit");
		return view;
		
	}
	/**
	 * 删除船舶基础资料数据
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/deleteBoatBaseDataManage")
	@ResponseBody
	public String deleteBoatBaseDataManage()throws Exception{
		PageData pd = new PageData();
		pd = this.getPageData();
		boatBaseDataManageService.deleteBoatDataManageInfo(pd);
		return null;
		
	}
	/**
	 * 批量删除船舶基础资料数据
	 * @throws Exception
	 */
	@RequestMapping(value="/deleteBoatBaseDataManageAll")
	@ResponseBody
	public String deleteBoatBaseDataManageAll() throws Exception{
		PageData pd = new PageData();
		pd = this.getPageData();
		String data = pd.getString("dataJsonStr");

		JSONArray items = JSONArray.fromObject(data);
		for(int i=0,size=items.size();i<size;i++){
			JSONObject item = items.getJSONObject(i);
			String id = item.getString("ID").trim();
			PageData pdq = new PageData();
			pdq.put("ID", id);
			boatBaseDataManageService.deleteBoatDataManageInfo(pdq);
		}
		return null;
		
	}
}
